package com.yuwei.parkinglot.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.yuwei.base.BaseViewModel
import com.yuwei.http.ApiService
import com.yuwei.http.entity.ParkingLotEntity
import com.yuwei.http.entity.ParkingLotEntityItem
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class ParkingLotViewModel @Inject constructor(
    val apiService: ApiService
): BaseViewModel(){
    val getParkingLotListSuccess by lazy { MutableLiveData<ParkingLotEntity>() }
    val getParkingLotDetailSuccess by lazy { MutableLiveData<ParkingLotEntityItem>() }
    val addParkingLotSuccess by lazy { MutableLiveData<ParkingLotEntityItem>() }
    val updateParkingLotSuccess by lazy { MutableLiveData<ParkingLotEntityItem>() }
    fun getParkingLotList(areaId: Int){
        viewModelScope.launch {
            executeNetwork({
                apiService.getParkingLotList(areaId)
            },getParkingLotListSuccess::postValue)
        }
    }
    fun getParkingLotDetail(id: Int){
        viewModelScope.launch {
            executeNetwork({
                apiService.getParkingLotDetail(id)
            },getParkingLotDetailSuccess::postValue)
        }
    }
    fun addParkingLot(param: ParkingLotEntityItem){
        viewModelScope.launch {
            executeNetwork({
                apiService.addParkingLot(param)
            },addParkingLotSuccess::postValue)
        }
    }
    fun updateParkingLot(id: Int,param: ParkingLotEntityItem){
        viewModelScope.launch {
            executeNetwork({
                apiService.updateParkingLot(id,param)
            },updateParkingLotSuccess::postValue)
        }
    }
}